package cn.tedu.supermarket.mapper;

import cn.tedu.supermarket.entity.ChangeGoods;
import cn.tedu.supermarket.entity.GoodsUser;

import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;
import java.util.List;

@Repository
public interface GoodsMapper {
    //商家
    @Insert("insert into goods values(null,#{name},#{cata},#{price},#{salesum},#{sum},#{imgurl},#{addtime})")
    Integer addGoods(GoodsUser user);

    @Select("select id from goods where name=#{name}")
    Integer selectGoods(String name);

    @Select("select * from goods order by id desc limit 0,8")
    List<GoodsUser> findAddtime();

    @Select("select * from goods order by salesum desc limit 0,8")
    List<GoodsUser> findSalesum();

    @Select("select * from goods where id=#{id}")
    GoodsUser selectById(int id);

    @Delete("delete from goods where id=#{id}")
    Integer deleteGoods(int id);

    //修改商品
    @Select("select name,price from goods where id=#{id}")
    ChangeGoods select(int id);
    @Update("update goods set name=#{name},price=#{price} where id=#{id}")
    Integer updateById(ChangeGoods changeGoods);

    //用户方面
    @Select("select * from goods")
    List<GoodsUser> selectAll();

    //查询商品
    @Select("select * from goods where cata=#{cata}")
    List<GoodsUser> selectGoodsByCata(String cata);

    @Select("select * from goods where name like '%${name}%'")
    List<GoodsUser> selectGoodsByName(String name);

    //修改销量与库存
    @Update("update goods set salesum=salesum+#{salesum},sum=sum-#{sum} where id=#{id}")
    Integer updateSumById(@Param("salesum")int salesum,@Param("sum")int sum,@Param("id")int id);
}
